class Solution {
public:
    string longestCommonPrefix(vector<string>& strs)
    {
        string str = strs[0];
        for (int i = 1; i < strs.size(); i++)
        {
            str = findcommand(str, strs[i]);
        }
        return str;
    }

    string findcommand(string& s1, string& s2)
    {
        int i = 0;
        while (i < min(s1.size(), s2.size()) && s1[i] == s2[i])i++;
        return s1.substr(0, i);
    }
};